<?php
class Admin_Form_ValidateCategory {
	
	private $_arrError;
	private $_arrData;
	
	public function __construct($arrParam = null,$options = null){
		$validate = new Zend_Validate();
		echo '<pre>';
			print_r($arrParam);
		echo '</pre>';		
		if($arrParam['name'] == null){
			$this->_arrError['name'] = 'Không được rỗng';
		}
		else {
			if(isset($arrParam['radio']) && $arrParam['radio'] == 0) $arrParam['parent'] = 0;
			$tblCategory = new Model_Table_category();
			echo '<pre>';
				print_r($arrParam);
			echo '</pre>';			
			if($arrParam['action'] == 'edit'){
				$result = $tblCategory->getItemWhere($arrParam,'edit');
			}else{
				$result = $tblCategory->getItemWhere($arrParam);
			}			
			if(count($result) >0){
				$this->_arrError['name'] = 'Đã tồn tại';
				$$arrParam['name'] = '';
			}		
		}
		
		$this->_arrData = $arrParam;
	}
	public function isValid(){
		$flag = false;
		if(count($this->_arrError) > 0){
			$flag = true;
		}
		return $flag;
	}
	public function getErrors(){
		return $this->_arrError;
	}
	
	public function getData(){
		return $this->_arrData;
	}
}